﻿using System;

namespace AgFractal.Fractals
{
    public class Mandelbrot : AbstractFractal
    {
        public Mandelbrot()
        {
            ID = new Guid("FBA092C7-04F7-4379-A4D8-C8CCDBFCF561");
            Name = Description = "Mandelbrot";
            R1 = -2.25; I1 = 1.5; R2 = 2.25; I2 = -1.5;
        }

        protected override short Calculate(double r, double i, short MaxIteration)
        {
            Complex c = new Complex(r, i);
            Complex z = new Complex(r, i);
            short j;
            for (j = 0; j < MaxIteration; j++)
            {
                if (z.Abs2() > 4) break;
                z = z.Sqr() + c;
            }
            return j;
        }
    }
}